package com.service.scheduling.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.googlecode.jsonrpc4j.JsonRpcHttpClient;
import com.service.dao.enums.*;
import com.service.dao.mapper.RwRecordMapper;
import com.service.dao.model.*;
import com.service.scheduling.dto.MemberStoreChange;
import com.service.scheduling.service.MemberStoreService;
import com.service.scheduling.service.RwRecordService;
import com.service.scheduling.service.SysConfigService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;
import org.web3j.crypto.Wallet;

import java.beans.Transient;
import java.net.URL;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Slf4j
@Service
public class RwRecordServiceImpl extends ServiceImpl<RwRecordMapper, RwRecord> implements RwRecordService {

    @Autowired
    private SysConfigService sysConfigService;

    @Autowired
    private MemberStoreService memberStoreService;


    @Override
    public List<RwRecord> listNotRechargeRecord(CoinsEnum coins, List<Integer> types) {
        return list(new QueryWrapper<RwRecord>().lambda()
                .eq(RwRecord::getPayStatus, RwRecordEnum.PayStatus.pass.getCode())
                .eq(RwRecord::getCoinsId, coins.getCode())
                .in(RwRecord::getAddrType, types)
                .eq(RwRecord::getOptType, RwRecordEnum.OptType.recharge.getCode())
                .isNotNull(RwRecord::getTxid)
                .eq(RwRecord::getFlag, true)
                .orderByDesc(RwRecord::getId)
                .last("LIMIT 100"));
    }

    /**
     * 提币列表
     * @return
     */
    @Override
    public List<RwRecord> listWithdrawalFILByCoinIdAndStatus() {
        return list(new QueryWrapper<RwRecord>().lambda()
                .eq(RwRecord::getPayStatus, RwRecordEnum.PayStatus.pass.getCode())
                .eq(RwRecord::getCoinsId, CoinsEnum.FIL.getCode())
                .eq(RwRecord::getOptType, RwRecordEnum.OptType.withdraw.getCode())
                .orderByDesc(RwRecord::getId)
                .last("LIMIT 100"));
    }

    @Override
    public int withdrawalERC20Usdt() {
        log.info("查询提币订单 --- start");
        List<RwRecord> withdrawsList = list(new QueryWrapper<RwRecord>().lambda()
                .eq(RwRecord::getPayStatus, RwRecordEnum.PayStatus.pass.getCode())
                .eq(RwRecord::getCoinsId, CoinsEnum.USDT.getCode())
                .eq(RwRecord::getAddrType, WalletEnums.Type.ERC20)
                .eq(RwRecord::getOptType, RwRecordEnum.OptType.withdraw.getCode())
                .orderByDesc(RwRecord::getId)
                .last("LIMIT 100"));

        List<RwRecord> withlist = withdrawsList.stream().map(item -> {
            RwRecord rwRecord = new RwRecord();
            //执行提币操作

//                item.getAddress();//提币地址
//                item.getRwNum();//数量

            //item.getCoinsId();//币种
            return item;
        }).collect(Collectors.toList());


        return 0;
    }


    @Override
    public List<RwRecord> selectByTxId(String hash) {
        return baseMapper.getRecordByTxId(hash);
    }

}
